package o;

import com.google.android.exoplayer2.Format;
import java.io.IOException;
import o.aea.e;

abstract class afq {
    private c ʻ;
    private int ʼ;
    private long ʽ;
    private aef ˊ;
    private boolean ˊॱ;
    private ady ˋ;
    private afn ˎ;
    private final afr ˏ = new afr();
    private long ˏॱ;
    private long ॱ;
    private boolean ॱˊ;
    private long ॱॱ;
    private int ᐝ;

    static class c {
        afn ˊ;
        Format ˏ;

        c() {
        }
    }

    static final class d implements afn {
        private d() {
        }

        public long ˋ(adv o_adv) throws IOException, InterruptedException {
            return -1;
        }

        public long ॱ(long j) {
            return 0;
        }

        public aea ˏ() {
            return new e(-9223372036854775807L);
        }
    }

    protected abstract boolean ˎ(anc o_anc, long j, c cVar) throws IOException, InterruptedException;

    protected abstract long ˏ(anc o_anc);

    void ˋ(ady o_ady, aef o_aef) {
        this.ˋ = o_ady;
        this.ˊ = o_aef;
        ˏ(true);
    }

    protected void ˏ(boolean z) {
        if (z) {
            this.ʻ = new c();
            this.ʽ = 0;
            this.ʼ = 0;
        } else {
            this.ʼ = 1;
        }
        this.ॱ = -1;
        this.ॱॱ = 0;
    }

    final void ˏ(long j, long j2) {
        this.ˏ.ˎ();
        if (j == 0) {
            ˏ(!this.ˊॱ);
        } else if (this.ʼ != 0) {
            this.ॱ = this.ˎ.ॱ(j2);
            this.ʼ = 2;
        }
    }

    final int ˊ(adv o_adv, adz o_adz) throws IOException, InterruptedException {
        switch (this.ʼ) {
            case 0:
                return ˏ(o_adv);
            case 1:
                o_adv.ॱ((int) this.ʽ);
                this.ʼ = 2;
                return 0;
            case 2:
                return ˏ(o_adv, o_adz);
            default:
                throw new IllegalStateException();
        }
    }

    private int ˏ(adv o_adv) throws IOException, InterruptedException {
        boolean z = true;
        boolean z2 = true;
        while (z2) {
            if (this.ˏ.ˏ(o_adv)) {
                this.ˏॱ = o_adv.ˊ() - this.ʽ;
                z2 = ˎ(this.ˏ.ॱ(), this.ʽ, this.ʻ);
                if (z2) {
                    this.ʽ = o_adv.ˊ();
                }
            } else {
                this.ʼ = 3;
                return -1;
            }
        }
        this.ᐝ = this.ʻ.ˏ.ʼॱ;
        if (!this.ॱˊ) {
            this.ˊ.ˎ(this.ʻ.ˏ);
            this.ॱˊ = true;
        }
        if (this.ʻ.ˊ != null) {
            this.ˎ = this.ʻ.ˊ;
        } else if (o_adv.ॱ() == -1) {
            this.ˎ = new d();
        } else {
            afp ˊ = this.ˏ.ˊ();
            if ((ˊ.ˊ & 4) == 0) {
                z = false;
            }
            this.ˎ = new afl(this.ʽ, o_adv.ॱ(), this, (long) (ˊ.ʻ + ˊ.ᐝ), ˊ.ˏ, z);
        }
        this.ʻ = null;
        this.ʼ = 2;
        this.ˏ.ˏ();
        return 0;
    }

    private int ˏ(adv o_adv, adz o_adz) throws IOException, InterruptedException {
        long ˋ = this.ˎ.ˋ(o_adv);
        if (ˋ >= 0) {
            o_adz.ˊ = ˋ;
            return 1;
        }
        if (ˋ < -1) {
            ॱ(-(ˋ + 2));
        }
        if (!this.ˊॱ) {
            this.ˋ.ˎ(this.ˎ.ˏ());
            this.ˊॱ = true;
        }
        if (this.ˏॱ > 0 || this.ˏ.ˏ(o_adv)) {
            this.ˏॱ = 0;
            anc ॱ = this.ˏ.ॱ();
            long ˏ = ˏ(ॱ);
            if (ˏ >= 0 && this.ॱॱ + ˏ >= this.ॱ) {
                long ˏ2 = ˏ(this.ॱॱ);
                this.ˊ.ˎ(ॱ, ॱ.ॱ());
                this.ˊ.ˋ(ˏ2, 1, ॱ.ॱ(), 0, null);
                this.ॱ = -1;
            }
            this.ॱॱ += ˏ;
            return 0;
        }
        this.ʼ = 3;
        return -1;
    }

    protected long ˏ(long j) {
        return (1000000 * j) / ((long) this.ᐝ);
    }

    protected long ˎ(long j) {
        return (((long) this.ᐝ) * j) / 1000000;
    }

    protected void ॱ(long j) {
        this.ॱॱ = j;
    }
}
